// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... namespace LargoBase.Motives { using LargoBase.Abstract; using LargoBase.Enums; using LargoBase.Localization; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Linq; /// /// Melodic Change. /// public sealed class MelodicChange : AbstractChange { #region Fields /// Melodic motive. private MelodicMotive melodicMotive; #endregion #region Constructors /// /// Initializes a new instance of the class. /// [UsedImplicitly] public MelodicChange() { } /// /// Initializes a new instance of the class. /// /// The given change. public MelodicChange(XElement xchange) : base(xchange) { Contract.Requires(xchange != null); //// if (xchange == null) { return; } this.MelodicFunction = DataEnums.ReadAttributeMelodicFunction(xchange.Attribute("MelodicFunction")); this.MelodicShape = DataEnums.ReadAttributeMelodicShape(xchange.Attribute("MelodicShape")); ////201509!!!!! this.MelodicFunction = (MelodicFunction)LibSupport.ReadByteAttribute(xchange.Attribute("MelodicFunction")); //// this.MelodicFunction = LargoBase.Enums.MelodicFunction.HarmonicFilling; ////201509!!!!! this.MelodicShape = (MelodicShape)LibSupport.ReadByteAttribute(xchange.Attribute("MelodicShape")); //// this.MelodicShape = LargoBase.Enums.MelodicShape.Original; this.MotiveNumber = XmlSupport.ReadIntegerAttribute(xchange.Attribute("MotiveNumber")); this.MusicalLineType = MusicalLineType.Melodic; this.ChangeType = MusicalChangeType.Melodic; } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. /// The given function. public MelodicChange(int givenBar, int givenLine, MelodicFunction givenFunction) : base(givenBar, givenLine, MusicalChangeType.Melodic) { this.MusicalLineType = MusicalLineType.Melodic; this.MelodicFunction = givenFunction; } /// /// Initializes a new instance of the class. /// /// The given bar. /// The given line. public MelodicChange(int givenBar, int givenLine) : base(givenBar, givenLine, MusicalChangeType.Melodic) { this.MusicalLineType = MusicalLineType.Melodic; } #endregion #region Properties - Xml /// /// Gets Xml representation. /// /// /// Property description. /// public override XElement GetXElement { get { var change = base.GetXElement; change.Add(new XAttribute("MelodicFunction", this.MelodicFunction)); change.Add(new XAttribute("MelodicShape", this.MelodicShape)); change.Add(new XAttribute("MotiveNumber", this.MotiveNumber ?? 0)); change.Add(new XAttribute("IsStop", this.IsStop)); return change; } } #endregion #region Properties /// Gets or sets class of melodic part. /// Property description. public MelodicFunction MelodicFunction { get; set; } /// /// Gets or sets the melodic shape. /// /// /// The melodic shape. /// public MelodicShape MelodicShape { get; set; } /// Gets or sets class of melodic part. /// Property description. public int? MotiveNumber { get; set; } /// /// Gets or sets the line letter. /// /// /// The line letter. /// public int? LineLetter { get; set; } /// /// Gets or sets the motivic change. /// /// /// The motivic change. /// public MotivicChangeType MotivicChange { get; set; } /// /// Gets or sets MelodicMotive. /// /// General musical property. public MelodicMotive MelodicMotive { get { if (this.MotiveNumber == null) { return null; } var isPrepared = this.melodicMotive != null; if (isPrepared) { return this.melodicMotive; } ////core bool isPrepared = (this.melodicMotive != null) && this.melodicMotive.Number == this.MotiveNumber && this.melodicMotive.CoreId == this.BlockModel.MelodicCore.Id; ////core if (isPrepared) { return this.melodicMotive; } //// if (this.BlockModel != null) { //// this.melodicMotive = this.BlockModel.Core.MelodicCore.GetMelodicMotive((int)this.MotiveNumber); //// } return this.melodicMotive; } set => this.melodicMotive = value; } #endregion #region String properties /// /// Gets MelodicTypeString. /// /// Property description. [UsedImplicitly] public string MelodicTypeString => LocalizedMusic.String("MelodicFunction" + ((byte)this.MelodicFunction).ToString(CultureInfo.CurrentCulture)); #endregion #region Static factory methods /// /// Gets the new end rhythmic change. /// /// The bar number. /// Index of the line. /// /// Returns object. /// public static MelodicChange GetNewMelodicStopChange(int barNumber, byte lineIndex) { Contract.Ensures(Contract.Result() != null); var change = new MelodicChange(barNumber, lineIndex) { MotivicChange = MotivicChangeType.MainMotiveStop }; return change; } #endregion #region Public methods /// /// Clones this instance. /// /// Returns object. public override object Clone() { var tmc = new MelodicChange(this.BarNumber, this.LineIndex) { MotiveNumber = this.MotiveNumber, MelodicFunction = this.MelodicFunction }; //// tmc.BlockModel = this.BlockModel; return tmc; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.AppendFormat(CultureInfo.CurrentCulture, base.ToString()); s.Append("," + this.LineTypeString); s.Append(", Motive " + this.MotiveNumber); return s.ToString(); } #endregion } }